package com.juc;

public class CreateThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        //通过继承Thread
        MyThread myThread = new MyThread();
        myThread.start();
        //通过实现Runnable接口
        Thread thread1 = new Thread(new MyRunnable());
        thread1.start();
        Thread t2 = new Thread(()->{
            System.out.println(Thread.currentThread().getName());

        });
        t2.start();
        t2.interrupt();//只是通知线程需要中断并不会立即执行,只是做个标记，给线程打了中断标记=true
        t2.isInterrupted();//判断是否打断
        t2.join();//异步变同步
        Thread.interrupted();//获取中断标记，中断并清除标记
        System.out.println("主线程");

    }

}
